package com.xidian.zhiancloud.controller.dangerWorkTicket;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.qo.dangerWorkTicket.WorkTicketQO;
import com.xidian.zhiancloud.service.dangerWorkTicket.WorkLedgerService;
import com.xidian.zhiancloud.vo.dangerWorkTicket.WorkTicketVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/WorkLedger")
public class WorkLedgerController extends BaseController {

    @Autowired
    private WorkLedgerService workLedgerService;

//    /**
//     * 根据id获取获取作业票
//     *
//     * @param id 作业票的id
//     * @return 查找到的作业票
//     */
//    @GetMapping("/getById")
//    public ResultDTO<WorkLedger> getById(@RequestParam("id") Long id) {
//        return ResultDTO.successOf(workLedgerService.getById(id), GeneralResponseEnums.SUCCESS);
//    }

    /**
     * 根据条件查询作业票
     *
     * @param workTicketQO 查询参数
     * @return 作业票列表
     */
    @GetMapping("/getListByQO")
    public ResultDTO<IPage<WorkTicketVO>> getListByQueryObject(WorkTicketQO workTicketQO){
        if(workTicketQO.getCurrent() == null || workTicketQO.getSize() == null){
            return ResultDTO.errorOf(GeneralResponseEnums.REQUEST_ERROR);
        }
        workTicketQO.setCompanyId(getSessionUserCompanyId());
        return ResultDTO.successOf(workLedgerService.getListByQO(workTicketQO), GeneralResponseEnums.SUCCESS);
    }
}
